﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImageRecognition2.Forms
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FormMatrix : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FormMatrix"/> class.
        /// </summary>
        public FormMatrix()
        {
            InitializeComponent();

            this.dataGridView1.Rows.Add();
            this.dataGridView1.Rows.Add();
            this.dataGridView1.Rows.Add();
            this.dataGridView1.Rows.Add();

            foreach(DataGridViewRow row in this.dataGridView1.Rows)
            {
                row.SetValues(0,0,0,0,0);
            }
        }

        /// <summary>
        /// Handles the Click event of the cbAddColumn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbAddColumn_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Columns.Add(new DataGridViewColumn());
        }

        /// <summary>
        /// Handles the Click event of the cbDeleteColumn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbDeleteColumn_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Columns.RemoveAt(this.dataGridView1.Columns.Count - 1);
        }

        /// <summary>
        /// Handles the Click event of the cbAddLine control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbAddLine_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Rows.Add(new DataGridViewRow());
        }

        /// <summary>
        /// Handles the Click event of the cbDeleteLine control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbDeleteLine_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Rows.RemoveAt(this.dataGridView1.Rows.Count-1);
        }

        /// <summary>
        /// Gets the byte array.
        /// </summary>
        /// <value>The byte array.</value>
        public byte[,] ByteArray
        {
            get
            {
                byte[,] aByte = new byte[5,5];

                for(int y=0;y<this.dataGridView1.Rows.Count;y++)
                {
                    byte[] aTempByte = new byte[this.dataGridView1.Rows[y].Cells.Count];
                    for (int x = 0; x < this.dataGridView1.Rows[y].Cells.Count;x++ )
                    {
                        aByte[x,y] = Convert.ToByte(this.dataGridView1.Rows[y].Cells[x].Value);
                    }
                }
                return aByte;
            }
        }

        /// <summary>
        /// Handles the Click event of the cbOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the cbCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
